const {app} = require('electron')
const path = require('path');
const os_1 = require('os')
const BlogBase = require(path.join(os_1.homedir(), app.name,'blog_templates','BlogBase'))
const path_1 = require('path')
class SoloBlog extends BlogBase{

    constructor(dataStore) {
        super(dataStore);
    }

    defineObject(extParams) {
        return {
            'articleTitle': extParams.hasOwnProperty('title') ? extParams['title'] : '' ,
            'articleContent': extParams.hasOwnProperty('content') ? extParams['content'] : '',
            'articleAbstract': extParams.hasOwnProperty('articleAbstract') ? extParams['articleAbstract'] : '',
            'articleTags': extParams.hasOwnProperty('articleTags') ? extParams['articleTags'] : '',
            'articlePermalink': extParams.hasOwnProperty('articlePermalink') ? extParams['articlePermalink']: '',
            'articleStatus': extParams.hasOwnProperty('status') ? extParams['status'] : 1,
            'articleSignId': extParams.hasOwnProperty('articleSignId') ? extParams['articleSignId'] : '1',
            'postToCommunity': false,
            'articleViewPwd': extParams.hasOwnProperty('articleViewPwd') ? extParams['articleViewPwd'] : ''
        }
    }

    title(extParams) {
        let infos = extParams['filepath'].split("/")
        if( infos.length >= 2 ){
            let title = infos[infos.length-2]
            extParams['title'] = title
        }
        if( infos.length > 2 ){
            extParams['articleTags'] = infos[infos.length-3]
        }
    }

    content(extParams) {
        let content = extParams['content']
        let header = this.contentHeader(content,extParams)
        extParams['articleAbstract'] = header
        let footer = this.contentFooter(content)
        extParams['content'] = header+"\n"+content+"\n"+footer
    }

    contentHeader(content, extParams){
        let linkInfo = this.topic(extParams) +
            "\n" +
            "**【猿起源落】** ，助力技术人成长！更多精彩文章第一时间在公众号发布哦！\n" +
            "![猿起源落](https://gitee.com/caoyangjie/pictures/raw/master/images/includes/7647283.png) \n\n"
        return linkInfo // + toc(content).content
    }

    topic(extParams){
        let config = this.dataStore.getTemplate()
        return "["+extParams['articleTags']+"]("+path_1.join(config['site'],'articles',config['publishDate'],extParams['series']+'.html)')+ " 已发布在个人微信公众号【猿起源落】，对文章进行了精简优化，欢迎大家关注!\n"
    }

    contentFooter(content){

    }

    ext(extParams) {
        extParams['articleSignId'] = 1
        let config = this.dataStore.getTemplate()
        let appends = config['publishDate'].split('-')
        if( extParams.hasOwnProperty('tocPath') ){
            appends.push(extParams['tocPath']+".html")
        }else{
            appends.push(new Date().getTime()+".html")
        }
        if( !extParams.hasOwnProperty('articlePermalink') ){
            extParams['articlePermalink'] = path_1.join('/articles',appends.join('/'))
        }
    }

    getName() {
        return '个人博客处理模板'
    }
}

module.exports = SoloBlog
